using Reflector.CodeModel;

namespace Reflector.CodeDom
{
    internal sealed class CodeDomLanguageWriter : ILanguageWriter
    {
        // Fields
        private readonly VisitorWriter visitor;
        private ILanguageWriterConfiguration configuration;
        private IFormatter formatter;

        // Methods
        /// <summary>
        /// Initializes a new instance of the <see cref="CodeDomLanguageWriter"/> class.
        /// </summary>
        /// <param name="formatter">The formatter.</param>
        /// <param name="configuration">The configuration.</param>
        public CodeDomLanguageWriter(IFormatter formatter,
            ILanguageWriterConfiguration configuration)
        {
            this.formatter = formatter;
            this.configuration = configuration;
            visitor = new VisitorWriter(formatter, configuration);
        }

        #region ILanguageWriter Members

        /// <summary>
        /// Writes the assembly.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteAssembly(IAssembly value)
        {
            visitor.VisitAssembly(value);
        }

        /// <summary>
        /// Writes the assembly reference.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteAssemblyReference(IAssemblyReference value)
        {
            visitor.VisitAssemblyReference(value);
        }

        /// <summary>
        /// Writes the event declaration.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteEventDeclaration(IEventDeclaration value)
        {
            visitor.VisitEventDeclaration(value);
        }

        /// <summary>
        /// Writes the expression.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteExpression(IExpression value)
        {
            visitor.VisitExpression(value);
        }

        /// <summary>
        /// Writes the field declaration.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteFieldDeclaration(IFieldDeclaration value)
        {
            visitor.VisitFieldDeclaration(value);
        }

        /// <summary>
        /// Writes the method declaration.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteMethodDeclaration(IMethodDeclaration value)
        {
            visitor.VisitMethodDeclaration(value);
        }

        public void WriteModule(IModule value)
        {
            visitor.VisitModule(value);
        }

        public void WriteModuleReference(IModuleReference value)
        {
            visitor.VisitModuleReference(value);
        }

        /// <summary>
        /// Writes the namespace.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteNamespace(INamespace value)
        {
            formatter.Write("Visiting the " + value.Name + " namespace");
            formatter.WriteLine();
            formatter.Write("It has " + value.Types.Count + " types");
            formatter.WriteLine();

        }

        /// <summary>
        /// Writes the property declaration.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WritePropertyDeclaration(IPropertyDeclaration value)
        {
            visitor.VisitPropertyDeclaration(value);
        }

        /// <summary>
        /// Writes the resource.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteResource(IResource value)
        {
            visitor.VisitResource(value);
        }

        /// <summary>
        /// Writes the statement.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteStatement(IStatement value)
        {
            visitor.VisitStatement(value);
        }

        /// <summary>
        /// Writes the type declaration.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteTypeDeclaration(ITypeDeclaration value)
        {
            visitor.VisitTypeDeclaration(value);
        }

        #endregion
    }
}